package monster.flight.admin.action.xtgl;

import com.opensymphony.xwork2.ActionContext;

import monster.comm.exception.InvalidParameterException;
import monster.comm.exception.ServiceException;
import monster.comm.log.ILog;
import monster.comm.log.LogService;
import monster.comm.util.ReturnConstant;
import monster.comm.util.ReturnVO;
import monster.comm.util.SessionBean;
import monster.comm.util.SysConstant;
import monster.flight.admin.manager.service.xtgl.UsersService;
import monster.flight.comm.entity.vo.Xt_users;
import monster.flight.comm.util.SchUtil;


/**
 * 创建信息=============
 * 类名: monster.flight.admin.action.xtgl.LoginAction
 * 类作用描述: 登录Action
 * 创建人： wanghong 
 * 创建时间： 2013-1-8 上午10:50:22
 * 修改信息1=============
 * 修改类型:     //1.修改bug 2.业务变化修改
 * 修改描述: 
 * 修改人：  
 * 修改时间：
 */

public class LoginAction{
   private String loginID;//登录ID
   private String passWord;//登录密码
   private UsersService usersService;//用户服务类
   private ReturnVO returnVO = new ReturnVO();
   private static ILog log = LogService.getLog(LoginAction.class);
   public ReturnVO getReturnVO(){
	   return returnVO;
   }
   public String getLoginID() {
		return loginID;
   }
	public void setLoginID(String loginID) {
		this.loginID = loginID;
	}
	public String getPassWord() {
		return passWord;
	}
	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
	public void setUsersService(UsersService usersService) {
		this.usersService = usersService;
	}
	/**
	*@Description: 登录验证,
	*@return String    
	*@throws
	 */
	public String login(){
			Xt_users po = new Xt_users();
			po.setLogin_name(loginID);
			po.setLogin_psw(passWord);
			try {
			    int r = usersService.login_chechUser(loginID);
				if(r==0){//没有此用户名
					returnVO.returnCode=ReturnConstant.IS_DEAL_FAIL;
					returnVO.returnDesc="没有此用户名";
				}else{
					po = usersService.login(po);
					if(po==null){
						returnVO.returnCode=ReturnConstant.IS_DEAL_FAIL;
						returnVO.returnDesc="密码错误";
					}else{//登录成功
						SessionBean sessionBean = SchUtil.setSession(po);
						ActionContext.getContext().getSession().put(SysConstant.SESSION_NAME, sessionBean);
						returnVO.returnCode=ReturnConstant.IS_DEAL_OK;
					}
				}
								
			} catch (InvalidParameterException e) {
				returnVO.returnCode=ReturnConstant.IS_PARAMS_ERR;
				log.error(e.getMessage(), e);				
			} catch (Exception e) {
				returnVO.returnCode=ReturnConstant.IS_ERR;
				log.error(e.getMessage(), e);				
				
			}
    	return "login";
    }
}
